package com.rr.learningdemo.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author RR
 * @date 2021/3/14 12:53
 */
public class WaitTest {

    static class WaitExample{
        synchronized void func1(){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("吃东西");
        }
        synchronized void func2(){
            System.out.println("上菜");
            this.notify();
        }
    }


    public static void main(String[] args) {
        WaitExample waitExample = new WaitExample();
        //这样子不行的
//        waitExample.func1();
//        waitExample.func2();
        ExecutorService executorService = Executors.newCachedThreadPool();
        executorService.execute(() -> waitExample.func1());
        executorService.execute(() -> waitExample.func2());
    }
}
